<!--
 * @Descripttion: 
 * @version: @ 1.0.0
 * @Author: ZJZ
 * @Date: 2021-06-10 15:55:32
 * @LastEditors: 朱江洲
 * @LastEditTime: 2022-05-12 16:23:05
-->
<template>
  <div>
    <el-drawer
      title="批次信息"
      :visible.sync="dialog.dialogAdminShow"
      :direction="direction"
      :with-header="false"
      size="60%"
      :modal="false"
      @close="drawerClose"
    >
      <div class="head">
        <div class="header">
          <div class="img">
            <img src="@/assets/images/icon-guanli.png" alt="" />
            <h3>员工信息</h3>
          </div>
          <div class="btn">
            <el-button
              type="primary"
              size="default"
              @click="edit"
              v-hasPermi="['system:user:edit']"
            >
              编辑
            </el-button>
            <el-dropdown>
              <el-button class="el-icon-more"></el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item
                  @click.native="resetPassword"
                  v-hasPermi="['system:user:resetPwd']"
                >
                  重置密码
                </el-dropdown-item>
                <el-dropdown-item
                  @click.native="frozen"
                  v-if="drawerData.isAdmin !== 1"
                  v-hasPermi="['system:user:changeStatus']"
                >
                  冻结
                </el-dropdown-item>
                <el-dropdown-item
                  @click.native="del"
                  v-if="drawerData.isAdmin !== 1"
                  v-hasPermi="['system:user:remove']"
                >
                  删除
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </div>
        <div class="footer">
          <div class="information">
            <span>姓名</span>
            <h4>{{ drawerData.nickName }}</h4>
          </div>
          <div class="information">
            <span>部门</span>
            <h4>{{ drawerData.dept.deptName }}</h4>
          </div>
          <div class="information">
            <span>手机号</span>
            <h4>{{ drawerData.phonenumber }}</h4>
          </div>
          <div class="information">
            <span>状态</span>
            <h4>{{ drawerData.status == 0 ? "激活" : "停用" }}</h4>
          </div>
        </div>
      </div>
      <div class="strip"></div>
      <div class="specific">
        <el-tabs v-model="activeName" type="border-card">
          <el-tab-pane label="详细资料" name="first">
            <div class="basics">基础信息</div>
            <div class="basics-information">
              <div class="subclass">
                <span>登录账号：{{ drawerData.nickName }}</span>
              </div>
              <div class="subclass">
                <span>角色：{{ drawerData.roleName }}</span>
              </div>
              <div class="subclass">
                <span>手机号：{{ drawerData.phonenumber }}</span>
              </div>
              <div class="subclass">
                <span>性别：{{ drawerData.sex == 0 ? "男" : "女" }}</span>
              </div>
              <div class="subclass">
                <span>邮箱：{{ drawerData.email }}</span>
              </div>
            </div>
            <div class="organization">组织信息</div>
            <div class="organization-information">
              <div class="subclass">
                <span>部门：{{ drawerData.dept.deptName }}</span>
              </div>
              <div class="subclass">
                <span>职位：{{ drawerData.post }}</span>
              </div>
              <div class="subclass">
                <span>直属上级：{{ drawerData.parentName }}</span>
              </div>
              <div class="subclass">
                <span>更新时间：{{ drawerData.updateTime }}</span>
              </div>
            </div>
            <div class="system">系统信息</div>
            <div class="basics-information">
              <div class="subclass">
                <span>创建人：{{ drawerData.createBy }}</span>
              </div>
              <div class="subclass">
                <span>创建时间：{{ drawerData.createTime }}</span>
              </div>
              <div class="subclass">
                <span>更新人：{{ drawerData.updataBy }}</span>
              </div>
              <div class="subclass">
                <span>更新时间：{{ drawerData.updataTime }}</span>
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane label="操作记录" name="second">
            <div
              class="operation"
              v-for="(item, index) in Operation"
              :key="index"
            >
              <div class="user">
                <div class="portrait">
                  <img :src="item.avatar" alt="" />
                </div>
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="item.createBy"
                  placement="top"
                >
                  <div class="name">{{ item.createBy }}</div>
                </el-tooltip>
              </div>
              <div class="record">
                <div class="time">{{ item.createTime }}</div>
                <div class="content">
                  <div>{{ item.content }}</div>
                </div>
              </div>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import { changeStatus, delUser } from "@/api/sys";
import { OperationRecord } from "@/api/CRM";
export default {
  props: {
    dialog: {
      type: Object,
      required: true,
    },
    drawerData: {
      type: Object,
      required: true,
    },
  },
  watch: {
    drawerData: {
      deep: true,
      handler() {
        if (this.drawerData !== {}) {
        }
      },
    },
  },
  data() {
    return {
      Operation: [], //操作记录
      drawerForm: {
        phone: "",
        userId: "",
        password: "",
        confirmPassword: "",
      },
      drawerRules: {},
      activeName: "first",
      direction: "rtl",
    };
  },
  created() {
    this.getOperationList();
  },
  methods: {
    // 操作记录
    getOperationList() {
      OperationRecord({
        columnId: 7,
        entryId: this.drawerData.userId,
      }).then((res) => {
        this.Operation = res.data;
      });
    },
    // 关闭抽屉
    drawerClose() {
      this.dialog.eject = false;
    },
    edit() {
      this.$parent.drawerData = this.drawerData;
      this.$parent.edit();
    },
    async del() {
      /*提示消息*/
      const confirmResult = await this.$confirm(
        "此操作将永久删除该名员工, 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).catch((err) => err);
      /*如果用户确认打印confirm,如果用户取消显示cancel*/
      if (confirmResult == "cancel") {
        return this.$message.info("已取消删除!");
      }
      if (confirmResult == "confirm") {
        let arr = [];
        arr.push(this.drawerData.userId);
        delUser(arr).then((res) => {
          this.$message.success("删除成功！");
          this.$parent.getTree();
        });
      }
      // console.log('确认了删除')
    },
    resetPassword() {
      this.dialog.resetPsd = true;
      this.$parent.resetForm.account = this.drawerData.phonenumber;
      this.$parent.resetForm.userId = this.drawerData.userId;
    },
    async frozen() {
      /*提示消息*/
      const confirmResult = await this.$confirm(
        "冻结员工账号后员工无法登录该系统，请问是否继续此操作？",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).catch((err) => err);
      /*如果用户确认打印confirm,如果用户取消显示cancel*/
      if (confirmResult == "cancel") {
        return this.$message.info("已取消冻结!");
      }
      if (confirmResult == "confirm") {
        changeStatus({ status: "1", userId: this.drawerData.userId }).then(
          (res) => {
            this.$message.success("冻结成功！");
          }
        );
      }
      // console.log('确认了删除')
    },
  },
};
</script>
<style lang="less" scoped>
/deep/.el-drawer.rtl {
  height: 96%;
  margin-top: 4%;
}
.head {
  padding-left: 29px;
  width: 100%;
  height: 155px;
  border-bottom: 1px solid #ececec;
  span {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999;
  }
  .header {
    display: flex;
    justify-content: space-between;
    .img {
      img {
        vertical-align: middle;
        margin-right: 12px;
      }
      h3 {
        display: inline-block;
      }
    }
  }
  .btn {
    margin-top: 15px;
  }
  .footer {
    margin-top: 20px;
    display: flex;
    .information {
      display: flex;
      flex-direction: column;
      margin-right: 80px;
      h4 {
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #2b2b2b;
        margin-top: 12px;
      }
    }
  }
}
.strip {
  width: 100%;
  height: 16px;
  background: #fafafa;
  border: 1px solid #ececec;
  /deep/.el-tabs__nav-scroll {
    background-color: #f5f8fa;
  }
}

/deep/ .el-tab-pane {
  padding-left: 24px;
}
.basics {
  margin-top: 30px;
  position: relative;
  font-size: 14px;
}
.basics::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 1px;
  width: 3px;
  height: 14px;
  background: #1267fa;
}

.system {
  margin-top: 40px;
  position: relative;
  font-size: 14px;
}
.system::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 1px;
  width: 3px;
  height: 14px;
  background: #1267fa;
}
.organization {
  margin-top: 40px;
  position: relative;
  font-size: 14px;
}
.organization::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 1px;
  width: 3px;
  height: 14px;
  background: #1267fa;
}
.organization-information {
  display: flex;
  flex-wrap: wrap;
  .subclass {
    width: 249px;
    margin-top: 30px;
    margin-right: 150px;
    span {
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #999999;
      line-height: 14px;
    }
  }
}

.basics-information {
  display: flex;
  flex-wrap: wrap;
  .subclass {
    width: 249px;
    margin-top: 30px;
    margin-right: 150px;
    span {
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #999999;
      line-height: 14px;
    }
  }
}
.operation {
  display: flex;
  .user {
    display: flex;
    .portrait {
      width: 30px;
      height: 30px;
      border-radius: 30px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 30px;
      }
    }
    .name {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      width: 100px;
      height: 30px;
      line-height: 30px;
      margin-left: 14px;
    }
  }
  .record {
    padding-left: 21px;
    margin-left: 44px;
    border-left: 1px dotted #dbdcdb;
    .time {
      font-size: 14px;
      position: relative;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #999999;
      line-height: 14px;
    }
    .time::before {
      content: "";
      position: absolute;
      left: -27px;
      width: 11px;
      height: 11px;
      background-color: #000;
      transform: rotate(45deg);
    }
    .content {
      padding-top: 10px;
      padding-bottom: 10px;
    }
  }
}
.el-dropdown {
  margin-left: 10px;
}
/deep/.thirdTab {
  .el-tabs__content {
    height: 100vh;
  }
}
/deep/.el-table__header-wrapper {
  background: #f2f2f2;
}
/deep/.el-tabs__content {
  height: 100vh;
  overflow: auto;
}
.newPsd {
  width: 266px;
  font-size: 12px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #3d4966;
  opacity: 50%;
  line-height: 30px;
}
</style>